function [cur,wrapping_size] = curvelet_limitedAngle_innerFading(imSize,radial,angular, lim_angl)
%
%
%author: Sebastian Schmelcher; version: 2012-04-24

identifier=['limitedAngle_innerFading_' num2str(lim_angl)];
map=get_indexStruct(identifier,imSize);

num_radial=length(map);

n=imSize(1);
m=imSize(2);

origin=get_origin([n,m]);





if(radial==0)
    cur=[0.928241517645832,1,0.928241517645832;1,1,1;0.928241517645832,1,0.928241517645832];
    point=[origin(1)-1 origin(2)-1; origin(1)+1 origin(2)+1 ];
    cur={cur,point,[0,0]};
    wrapping_size=[3, 3];
    return;
end

if(radial>num_radial)
    return;
end

if(angular>map(radial))
    return;
end




%every wedge is suppossed to overlap in a region of 1/6 of its width with
%the neigbooring wedge. Therefore the limited angle is shortened by 1/3 of
%the wedgesize to make sure the outer wedges do not reach into the zero
%region.

curvelet_width=2*lim_angl/(map(radial)+2/3);
lim_angl=lim_angl-1/3*curvelet_width;
curvelet_dir=-lim_angl/2+(angular-.5)*curvelet_width;
if(angular>map(radial)/2)
    curvelet_dir=curvelet_dir+180-lim_angl;
end

curvelet_dir=pi*curvelet_dir/180;
curvelet_dir=angle(exp(1i*curvelet_dir));
curvelet_width=pi*curvelet_width/180;
curvelet_supp_width=4/3*curvelet_width; 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[point,shift,wrapping_size]=get_Curvelet_point_shift(radial,curvelet_dir,curvelet_supp_width,origin,n,m,num_radial);


% [X,Y]=meshgrid(1-origin(1):n-origin(1),1-origin(2):m-origin(2));
% [theta,rad]=cart2pol(X,Y);
% rad=(2^(-radial)).*rad;
% theta=angle(exp(1i*(theta-curvelet_dir)))/curvelet_width*2;
% if(radial==num_radial)
%     cur=lastRadialWindow(rad).*angularWindow(theta); %no upper limit
% else
%     cur=radialWindow(rad).*angularWindow(theta);
% end

%%%%%%%%% faster %%%%%%%%%%%%
[X,Y]=meshgrid(point(3)-origin(1):point(4)-origin(1),point(1)-origin(2):point(2)-origin(2));
[theta,rad]=cart2pol(X,Y);
rad=(2^(-radial)).*rad;
theta=angle(exp(1i*(theta-curvelet_dir)))/curvelet_width*2;
if(radial==num_radial)
    cur2=lastRadialWindow(rad).*angularWindow(theta); %no upper limit
else
    cur2=radialWindow(rad).*angularWindow(theta);
end
   


cur={cur2,point,shift};


% -------------------------------------------------------------------------
function x = lastRadialWindow(r)
%no upper limit
rSize=size(r);

x= (r>=(5/6));
x=x+cos((5*ones(rSize)-6*r)*(pi/2)).*(r>=(2/3)) .* (r<(5/6));





% -------------------------------------------------------------------------

function x = angularWindow(t)
t=abs(t);
tSize=size(t);


x=(t<=2/3);
x=x+((t<=4/3).*(t>2/3) .* cos(  (3/2*t-ones(tSize))*(pi/2) ));

% x=(t<=(1/3));
% x=x+((t<=(2/3)) .* (t>1/3)).*cos(  (3*t-ones(tSize))*(pi/2) );



% -------------------------------------------------------------------------
function x = radialWindow(r)
rSize=size(r);

x=( (r>=(5/6)) .* (r<=(4/3)) );
x=x+cos((5*ones(rSize)-6*r)*(pi/2)).*(r>=(2/3)) .* (r<(5/6));
x=x+cos((3*r-4*ones(rSize))*(pi/2)).*(r>(4/3)) .* (r<=(5/3));

